#ifndef COPYTHREAD_H
#define COPYTHREAD_H

#include <QTimer>
#include <QProgressDialog>
#include <QFile>
#include <QRunnable>
#include <QString>
#include <QMutex>
#include <QMutexLocker>
#include <QMap>

typedef QSharedPointer<QProgressDialog> QProgressDialogPtr;
typedef QSharedPointer<QMutex> QMutexPtr;

Q_DECLARE_METATYPE(QProgressDialogPtr)

class CopyThread: public QObject, public QRunnable
{
    Q_OBJECT
public:
    CopyThread(const QString &filePathFromPtr, const QString &filePathToPtr, QProgressDialogPtr progressPtr, QObject *parent);
    ~CopyThread();
    QString getDestination();

public slots:
    void stopCopying();
    void bytesWrittenProgress();

signals:
    void showProgressDialog(QProgressDialogPtr progressPtr);
    void setProgressValue(int value);

private:
    void copyFile();
    void doCopy();
    void run();

private:
    QFile                           m_fileFrom;
    QFile                           m_fileTo;
    QProgressDialogPtr              m_progressPtr;
    bool                            m_flag;
    QTimer                          m_timer;
    QMutex                          m_mutexFileWrite;
    static QMap<QString, QMutexPtr> m_strMutexMap;
    static const int                m_progressMax;
    static const int                m_progressMin;
};


#endif // COPYTHREAD_H
